<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*,hotel.entity.*"%>
<%@include file="../link.html"%>
<!-- 更换房间页面 -->
<script type="text/javascript">
$(document).ready(function() {
	
	$("#btn-close").click( function () { 
		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭 
	});
	
	$("#btn-submit").click( function () {
		$.ajax({
	        type:"post",
	        url:'changeRoom',
	        data: $('#changeForm').serialize(),//表单数据
	        success: function(data){
				layer.msg('添加成功', {icon: 1, time: 800}, function(){//关闭后执行的操作
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭 
					});  
	        }
	    });
	});
});

layui.use('form', function(){
	var form = layui.form;
	form.render();
	var needAmount=1;
	//监听CheckBox
	form.on('checkbox', function(data){
		  if(data.elem.checked){
			  $("input[name='newRoom']").val(data.value);
			  $("#selectedRoom").val(data.elem.title);
		  }
		  else{
			  $("input[name='newRoom']").val('');
			  $("#selectedRoom").val(''); 
		  }
	});
});
</script>

<div style="padding-top:25px;">
	<form id='changeForm' class="layui-form"  action="#">
		<input type="hidden" name='itemid' value='${itemid}'>
		<input type="hidden" name='oldRoom' value='${oldRoom}'>
		<input type="hidden" name='newRoom' value="">
	
		<div class="layui-form-item">
			<label class="layui-col-md2 layui-col-md-offset3">当前房间</label>
			<div class="layui-col-md4">
				<input class="form-control" readonly value="${roomNo}">
			</div>
		</div>
		
		<div class='layui-form-item'>
			<label class='layui-col-md2 layui-col-md-offset3'>更换房间</label>
			<div class="layui-col-md4">
				<input id='selectedRoom' class="form-control" readonly value="">
			</div>
		</div>
		
		<div class='layui-form-item'>
			<div class="layui-col-md5 layui-col-md-offset4">
		<%
		List<Room> roomList=(List<Room>)request.getAttribute("roomList");
		Map<Integer,Room> available=(Map<Integer,Room>)request.getAttribute("availableMap");
		for(Room r:roomList){
			if(available.containsKey(r.getRoomid()))
				out.print("<div class='layui-col-sm6'><div class='layui-input-block'>"
					+"<input type='checkbox' value='"+r.getRoomid()+"' title='"
					+r.getNo()+"'></div></div>");
			else
				out.print("<div class='layui-col-sm6'><div class='layui-input-block'>"
					+"<input type='checkbox' value='"+r.getRoomid()+"' title='"
					+r.getNo()+"' disabled></div></div>");
		}
		%>
			</div>
		</div>
		
		<div class="box-footer"></div>
		
		<div class="layui-form-item">
			<label class="layui-col-md2 layui-col-md-offset3"></label>
			<div class="layui-col-md4">
				<div class="pull-right">
					<button id='btn-submit' type="button" class="btn btn-primary">
						<i class="fa fa-floppy-o "></i> 确定
					</button>
					<button id="btn-close" class="btn btn-close btn-primary" type="button">
						<i class="fa fa-remove"></i> 关闭
					</button>
				</div>
			</div>
		</div>
	</form>
</div>